﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using KCL.Code.Data;

namespace KCL.Code.Business
{
    public class MaterialImportServices
    {
        public static MaterialImport GetMaterialImportByID(int id)
        {
            return (new MaterialImportDAO()).GetMaterialImportByID(id);
        }

        public static List<MaterialImport> GetAllMaterialImports()
        {
            return (new MaterialImportDAO()).GetAllMaterialImports();
        }

        public static bool Insert(MaterialImport mi)
        {
            MaterialImportDAO mimpDAO = new MaterialImportDAO();
            mi.id = mimpDAO.GetMaxID() + 1;
            if (mimpDAO.Insert(mi))
            {
                (new MaterialDAO()).UpdateMaterialQuantity(mi.materialCode);
                return true;
            }
            return false;
        }

        public static bool Update(MaterialImport mi)
        {
            if ((new MaterialImportDAO()).Update(mi))
            {
                (new MaterialDAO()).UpdateMaterialQuantity(mi.materialCode);
                return true;
            }
            return false;
        }

        public static bool Delete(MaterialImport mi)
        {
            if ((new MaterialImportDAO()).Delete(mi))
            {
                (new MaterialDAO()).UpdateMaterialQuantity(mi.materialCode);
                return true;
            }
            return false;
        }
    }
}